package com.example.myapplication3;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = findViewById(R.id.zhangsan);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, StudentActivity.class);
                intent.putExtra("name", "Zhangsan");
                intent.putExtra("age", 21);
                startActivityForResult(intent, 0);
            }
        });
        Button button1 = findViewById(R.id.Lisi);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, StudentActivity.class);
                intent.putExtra("name", "Lisi");
                intent.putExtra("age", 22);
                startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


            String str=data.getStringExtra("result");
            if(requestCode==0){
                TextView textView=findViewById(R.id.text1);
                textView.setText(str+" 这是张三");
            }
            else if(requestCode==1){
                TextView textView=findViewById(R.id.text1);
                textView.setText(str+" 这是李四");
            }

    }
}